package com.servlet.dba;

import com.enitiy.Dba;
import com.service.dba.DbaServiceImpl;
import jdk.nashorn.internal.ir.IfNode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/24 15:30
 * 项目名称 SHUSHAN
 */
@WebServlet("/dbaLogin")
public class DbaLogin extends HttpServlet {
    @Override//管理员登录
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String num = req.getParameter("num");
        String pwd = req.getParameter("pwd");
        DbaServiceImpl dsi = new DbaServiceImpl();
        Dba dba = dsi.DbaLogin(Integer.parseInt(num), pwd);

        System.out.println("num = " + num);
        System.out.println("pwd = " + pwd);
        System.out.println("dba = " + dba);
        if (dba!=null){
            System.out.println("登陆成功！");
            String name = dba.getName();
            int dnum = dba.getDnum();
            req.setAttribute("name",name);
            req.setAttribute("num",dnum);
            req.getRequestDispatcher("/page/dba/dbaMain.jsp").forward(req,resp);
        }else {
            System.out.println("登录失败！");
            req.getRequestDispatcher("/page/dba/dbaLogin.html").forward(req,resp);
        }
    }
}
